package net.fivegoods.web;

import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import net.fivegoods.entity.impl.slim3.VolunteerModel;

import org.slim3.datastore.Datastore;

@Path("/volunteers")
public class Volunteers {
    
    @GET
    @Path("/{key}")
    public VolunteerModel get(@PathParam("key") String encodedKey) {
        return VolunteerModel.getByKeyString(encodedKey);
    }
    @POST
    public VolunteerModel create(
            @FormParam("guid") String guid) {
        VolunteerModel volunteer = new VolunteerModel();
        volunteer.setGuid(guid);
        volunteer.save();
        return volunteer;
    }
    @PUT
    public VolunteerModel update(@FormParam("key") String encodedKey) {
        VolunteerModel volunteer = VolunteerModel.getByKeyString(encodedKey);
        volunteer.setKey(Datastore.stringToKey(encodedKey));
        volunteer.save();
        return volunteer;
    }
    @DELETE
    @Path("/{key}")
    public void delete(@PathParam("key") String encodedKey) {
        VolunteerModel.deleteByKeyString(encodedKey);
    }
}
